%% AIM IN THIS SCRIPT IS TO 
%% A) CREATE AN ECOG-STRUCTURE (THE BASIC DATA STRUCTURE) OF THE WHOLE RECORDED TIMESERIES 
%% COMMENTS INDICATE WHERE USER DATA ARE REUIRED. 
%%
%% STEP 1: CREATE THE BASIC DATA STRUCTURE
% ***User parameters
nameOfFirstDataChannel='Wav11';
triggerChannelNames={'triggerANIN3','triggerANIN4'}; %Trigger channels will be included in the order specified here. Trigger channels will be multiplied by 2^channelNumber (e.g. first 2^0, second 2^1 etc) This way it is easy to extract triggers that came from the same channel even if they were overlapping. Ideally let your trigger channel contain only ones and zeros
triggerChannelOffsets=[0 0 0];
triggerChannelMultipliers=[2^0 2^3 2^4];


% create ecog structure 
load(['Wav1' num2str(1)])
ecog.data=zeros(256,length(data));
for nBlocks=1:4
    for k=1:64
        load(['Wav' num2str(nBlocks) num2str(k)]);
        ecog.data((nBlocks-1)*64+k,:)=data;
    end
end

baselineDurMs=0;
sampDur=1000/params.sampFreq;
ecog=ecogRaw2Ecog(ecog.data,baselineDurMs,sampDur,[]);

%add trigger 
for k=1:length(triggerChannelNames)
    load(triggerChannelNames{k})
    if k==1
        ecog.triggerTS=data*triggerChannelMultipliers(k)+triggerChannelOffsets(k);
    else 
        ecog.triggerTS=ecog.triggerTS+data*triggerChannelMultipliers(k)+triggerChannelOffsets(k);
    end
end
save -v7.3  ecog ecog

%%